package com.yxw.springmvc.test;

/**
 * Created by hp on 2016/10/14.
 */
public class Account1 {
    private String name;
    private int amount;

    public Account1(String name,int amount){
        this.name = name;
        this.amount = amount;
    }

    public synchronized void deposit(int emp){
        int i = this.amount;
        i += emp;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.amount = i;
    }

    public synchronized void withdraw(int emp){
        int i = this.amount;
        i -= emp;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.amount = i;
    }

    public int getBalances(){
        return this.amount;
    }
}
